package com.foreknow.elm.controller;

import com.foreknow.elm.po.User;
import com.foreknow.elm.service.UserService;
import com.foreknow.elm.service.impl.UserServiceImpl;

import javax.servlet.http.HttpServletRequest;

public class UserController {
    /**
     * 请求地址  http://localhost:8080/MavenElmWebProject/UserController/getUserByIdByPass?userId=kj&password=1
     * @param request
     * @return
     */

    public User getUserByIdByPass(HttpServletRequest request){
        //获取请求参数
        String userId= request.getParameter("userId");
        String password= request.getParameter("password");
        //调用Service层的方法
        UserService service = new UserServiceImpl();
        User user = service.getUserByIdByPass(userId,password);
        return user;
    }
    /**
     * 请求地址  http://localhost:8080/MavenElmWebProject/UserController/getUserById?userId=8080
     * @param request
     * @return
     */
    public int getUserById(HttpServletRequest request){
        //获取请求参数
        String userId= request.getParameter("userId");
        //调用Service层的方法
        UserService service = new UserServiceImpl();
       int user =  service.getUserById(userId);
        return user;
    }

    /**
     * 请求地址   http://localhost:8080/MavenElmWebProject/UserController/saveUser?userId=1212121&password=123123&userName=蓝精灵&userSex=1
     * @param request
     * @return
     */
    public int saveUser(HttpServletRequest request){
        //获取请求参数
        String userId= request.getParameter("userId");
        String password=request.getParameter("password");
        String userName = request.getParameter("userName");
        String userSex = request.getParameter("userSex");
        //调用Service层的方法
        UserService service = new UserServiceImpl();
        int add = service.saveUser(userId,password,userName,Integer.valueOf(userSex));
        return add;
    }
}
